{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "377fc8c4",
   "metadata": {},
   "source": [
    "|  列表方法  | Description | example | 备注  \n",
    "| ----------- | ----------- | ----------- | ----------- |\n",
    "|  append      |   将对象追加到列表的末尾      | names.append(\"\") |\n",
    "|  clear   | 从列表中删除所有项目       | list.clear(names)\n",
    "|  copy | 内建的copy方法，返回列表的副本 | list.copy(names) |\n",
    "|  count | 内置的计数方法，返回值的出现次数 | names.count() |\n",
    "|  extend | 扩展（可迭代的内置方法），从可迭代对象中追加元素扩展列表 | names.extend() |\n",
    "|  index | list实例的索引方法,返回值的第一个索引,如值不存在，则引发ValueError | names.index()| \n",
    "|  insert | 插入索引/对象的的内置方法，在索引前插入对象 | names.insert(数值，————) |\n",
    "|  pop | 删除并返回索引处的项（默认为最后一项）如果列表为空或索引超出范围，则引发IndexError | names.pop(数值) |\n",
    "|  remove | 删除内置函数的方法，列表实例删除第一个出现的值，若值不存在，则引发ValueError | names.remove() |\n",
    "|  reverse | 内置函数反转，反向*在适当位置* | list.reverse() |\n",
    "|  sort | 分类内建函数的方法，列表实例将列表按升序/降序排序 | list.sort() |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "8694e005",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "ce205f88",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "69191abc",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"linhan\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "d77541ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Marry', 'Jan', 'Jack', 'linhan']"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "f7f34d55",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function clear:\n",
      "\n",
      "clear() method of builtins.list instance\n",
      "    Remove all items from list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.clear)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "d2c01dfa",
   "metadata": {},
   "outputs": [],
   "source": [
    "list.clear(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "da4ef84b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "062cc507",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function copy:\n",
      "\n",
      "copy() method of builtins.list instance\n",
      "    Return a shallow copy of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.copy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "6eea1cc0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list.copy(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "248754a5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function count:\n",
      "\n",
      "count(value, /) method of builtins.list instance\n",
      "    Return number of occurrences of value.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "463369fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.count(\"linhan\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "f5883e8f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.count(\"Mike\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "bf1e1fe7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function extend:\n",
      "\n",
      "extend(iterable, /) method of builtins.list instance\n",
      "    Extend list by appending elements from the iterable.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.extend)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "a28fc258",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.extend(\"111\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "baf1c78f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Marry', 'Jan', 'Jack', '1', '1', '1']"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "1b64c980",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function index:\n",
      "\n",
      "index(value, start=0, stop=9223372036854775807, /) method of builtins.list instance\n",
      "    Return first index of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "56b8b751",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.index(\"Mike\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "9d87be26",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "'linhan' is not in list",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [54]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m names \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMike\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMarry\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mJan\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mJack\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m----> 2\u001b[0m \u001b[43mnames\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mindex\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mlinhan\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "\u001b[1;31mValueError\u001b[0m: 'linhan' is not in list"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.index(\"linhan\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "94883b6e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "8d291b6b",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.insert(1,\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "f092be02",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Alex', 'Marry', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "958b15bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.insert(0,\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "8b70fab5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Alex', 'Mike', 'Marry', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "3f1b5ecc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "0a183c37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jack'"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.pop(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "9d90e33f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jan'"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.pop(-2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "58db054b",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "pop index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [72]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m names \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMike\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMarry\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mJan\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mJack\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m----> 2\u001b[0m \u001b[43mnames\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpop\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "\u001b[1;31mIndexError\u001b[0m: pop index out of range"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.pop(-5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "0fcfadb9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "05b12e0d",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.remove(\"Mike\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "69b7fb19",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "0c5823d5",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "list.remove(x): x not in list",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [88]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m names \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMike\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMarry\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mJan\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mJack\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m----> 2\u001b[0m \u001b[43mnames\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mremove\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mlinhan\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "\u001b[1;31mValueError\u001b[0m: list.remove(x): x not in list"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.remove(\"linhan\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "c9813680",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function reverse:\n",
      "\n",
      "reverse() method of builtins.list instance\n",
      "    Reverse *IN PLACE*.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.reverse)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "0e1ec85c",
   "metadata": {},
   "outputs": [],
   "source": [
    "list = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "list.reverse()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "03f421a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Jan', 'Marry', 'Mike']"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "8b1425eb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sort:\n",
      "\n",
      "sort(*, key=None, reverse=False) method of builtins.list instance\n",
      "    Sort the list in ascending order and return None.\n",
      "    \n",
      "    The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n",
      "    order of two equal elements is maintained).\n",
      "    \n",
      "    If a key function is given, apply it once to each list item and sort them,\n",
      "    ascending or descending, according to their function values.\n",
      "    \n",
      "    The reverse flag can be set to sort in descending order.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.sort)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "4b1c3df7",
   "metadata": {},
   "outputs": [],
   "source": [
    "list = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "list.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "1759130c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Jan', 'Marry', 'Mike']"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "9fda3dd4",
   "metadata": {},
   "outputs": [],
   "source": [
    "list = [\"Mike\",\"Marry\",\"Mike\",\"Jan\",\"Jack\",\"Jan\"]\n",
    "list.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "49237abd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Jan', 'Jan', 'Marry', 'Mike', 'Mike']"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "92395d1b",
   "metadata": {},
   "outputs": [],
   "source": [
    "list = [\"Mike\",\"Marry\",\"Jan\",\"Jack\",\"Jan\"]\n",
    "list.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "77eb64cb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Jan', 'Jan', 'Marry', 'Mike']"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "80a20aa5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
